package com.woniu.controller;

import com.woniu.entity.Customer;
import com.woniu.entity.Customer;
import com.woniu.service.AddressService;
import com.woniu.service.CustomerService;
import com.woniu.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @GetMapping()
    public ResponseUtil findAll() {
        return customerService.findAll();
    }
    /**
     * 添加客户
     */
    @PostMapping("/add")
    public ResponseUtil addCustomer(@RequestBody Customer customer) {
        return customerService.addCustomer(customer);
    }

    /**
     * 删除客户
     */
    @GetMapping("/delete/{id}")
    public ResponseUtil deleteCustomer(@PathVariable("id") Integer customerId) {
        return customerService.deleteCustomer(customerId);
    }

    /**
     * 更新客户
     */
    @PostMapping("/update")
    public ResponseUtil updateCustomer(@RequestBody Customer customer) {
        return customerService.updateCustomer(customer);
    }

    /**
     * 根据ID查询客户
     */
    @GetMapping("/{id}")
    public ResponseUtil getCustomerById(@PathVariable("id") Integer customerId) {
        return customerService.getCustomerById(customerId);
    }

    /**
     * 查询所有客户
     */
    @GetMapping("/list")
    public List<Customer> getAllCustomers() {
        return customerService.getAllCustomers();
    }

    /**
     * 模糊查询客户
     */
    @GetMapping("/search")
    public List<Customer> searchCustomers(@RequestParam("keyword") String keyword) {
        return customerService.searchCustomers(keyword);
    }

    /**
     * 停用客户
     */
    @GetMapping("/disable/{id}")
    public ResponseUtil disableCustomer(@PathVariable("id") Integer customerId) {
        return customerService.disableCustomer(customerId);
    }

    /**
     * 启用客户
     */
    @GetMapping("/enable/{id}")
    public ResponseUtil enableCustomer(@PathVariable("id") Integer customerId) {
        return customerService.enableCustomer(customerId);
    }
}